package com.tszs.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tszs.biz.CashManagementTableBiz;
import com.tszs.entity.CashManagementTable;
import com.tszs.entity.CashManagementTableExample;
import com.tszs.util.CallBack;
import com.tszs.util.Uuid;

import net.sf.json.JSONObject;

/**
 * @类名:AdministratorTableController
 * @类描述：财务提现
 * @创建时间：2019-03-22 13:07:07
 * @创建人：王俊
 * @author Administrator
 *
 */
@Controller
public class CashManagementTableController {
	/**
	 * @CashManagementTableBiz
	 * @创建时间:201903-21 13:14:14
	 */
	@Autowired
	private CashManagementTableBiz cashManagementTableBiz;

	/**
	 * @方法名:CashManagementTablePage
	 * @方法描述：提现管理分页 
	 * @创建时间：2019-03-22 13:07:07
	 * @创建人：王俊
	 * @author Administrator
	 *
	 */
	@RequestMapping("pc/admin/CashManagementTablePage")
	public void CashManagementTablePage(HttpServletRequest request, HttpServletResponse response) {
		response.setContentType("text/xml; charset=UTF-8");
		response.setContentType("text/html;charset=utf-8");
		int page = Integer.parseInt(request.getParameter("page"));
		int limit = Integer.parseInt(request.getParameter("limit"));
		String begin = request.getParameter("type3");
		String end = request.getParameter("type4");
		CashManagementTable example = new CashManagementTable();
		example.setPage((page - 1) * limit);
		example.setLimit(limit);
		if (!(null == begin) && !(null == end)) {
			if (!"".equals(begin) && !"".equals(end)) {
				begin = begin + " 00:00:01";
				end = end + " 23:59:59";
				example.setBegin(begin);
				example.setEnd(end);
			}
		}
		List<CashManagementTable> selectByExample = cashManagementTableBiz.selectByExamplePage(example);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("count", selectByExample.size());
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < selectByExample.size(); i++) {
			Map<String, Object> mapData = new HashMap<String, Object>();
			mapData.put("cId", i + 1);
			mapData.put("CellPhoneNumber", selectByExample.get(i).getCellPhoneNumber());
			mapData.put("RealName", selectByExample.get(i).getRealName());
			if (selectByExample.get(i).getCashWithdrawalMethod().equals("0")) {
				mapData.put("CashWithdrawalMethod", "支付宝");
			} else if (selectByExample.get(i).getCashWithdrawalMethod().equals("1")) {
				mapData.put("CashWithdrawalMethod", "微信");
			} else {
				mapData.put("CashWithdrawalMethod", "银联");
			}

			if (selectByExample.get(i).getcStatic().equals("0")) {
				mapData.put("cashWithdrawalStatus", "提交申请中");
			} else if (selectByExample.get(i).getcStatic().equals("1")) {
				mapData.put("cashWithdrawalStatus", "审核中");
			} else if (selectByExample.get(i).getcStatic().equals("2")) {
				mapData.put("cashWithdrawalStatus", "审核通过");
			} else {
				mapData.put("cashWithdrawalStatus", "拒绝通过");
			}
			mapData.put("cReateEndtime", selectByExample.get(i).getcReateEndtime());
			mapData.put("CashWithdrawalAmoun", selectByExample.get(i).getCashWithdrawalAmount());
			mapData.put("AmountOfAccountPayable", selectByExample.get(i).getAmountOfAccountPayable());
			mapData.put("cCreateTime", selectByExample.get(i).getcCreateTime());
			mapData.put("button", "<a href=\"javascript:table('" + selectByExample.get(i).getcId()
					+ "')\" class=\"layui-btn layui-btn-danger layui-btn-xs\" style=''>查看详情</a>");
			list.add(mapData);
		}
		map.put("data", list);
		JSONObject json = JSONObject.fromObject(map);
		new CallBack().textObject(json, response);
	}

	/**
	 * @方法名:findIdWithdrawal
	 * @方法描述：根据ID查询提现详情 @创建时间：2019-03-22 13:07:07
	 * @创建人：王俊
	 * @author Administrator
	 *
	 */
	@RequestMapping("pc/admin/findIdWithdrawal")
	public void findIdWithdrawal(HttpServletRequest request, HttpServletResponse response) {
		CashManagementTableExample example = new CashManagementTableExample();
		com.tszs.entity.CashManagementTableExample.Criteria ca = example.createCriteria();
		ca.andCIdEqualTo(request.getParameter("id"));
		List<CashManagementTable> selectByExample = cashManagementTableBiz.selectByExample(example);
		List<CashManagementTable> list = new ArrayList<>();
		for (int i = 0; i < selectByExample.size(); i++) {
			CashManagementTable c = new CashManagementTable();
			c.setcId(selectByExample.get(i).getcId());
			c.setCellPhoneNumber(selectByExample.get(i).getCellPhoneNumber());
			c.setWithdrawalsId(selectByExample.get(i).getWithdrawalsId());
			if (selectByExample.get(i).getCashWithdrawalMethod().equals("0")) {
				c.setCashWithdrawalMethod("支付宝");
			} else if (selectByExample.get(i).getCashWithdrawalMethod().equals("1")) {
				c.setCashWithdrawalMethod("微信");
			} else {
				c.setCashWithdrawalMethod("银联");
			}
			c.setProcedureCost(selectByExample.get(i).getProcedureCost());
			c.setRealName(selectByExample.get(i).getRealName());
			c.setCashWithdrawalAmount(selectByExample.get(i).getCashWithdrawalAmount());
			c.setAmountOfAccountPayable(selectByExample.get(i).getAmountOfAccountPayable());
			c.setcCreateTime(selectByExample.get(i).getcCreateTime());
			c.setOperator(selectByExample.get(i).getOperator());
			c.setcReateEndtime(selectByExample.get(i).getcReateEndtime());
			if (selectByExample.get(i).getcStatic().equals("0")) {
				c.setcStatic("<a href=\"javascript:table('0','" + selectByExample.get(i).getcId()
						+ "')\"  class=\"layui-btn layui-btn-danger layui-btn-xs\">审核通过</a><a href=\"javascript:table('1','"
						+ selectByExample.get(i).getcId() + "')\" class=\"layui-btn layui-btn-xs\">拒绝通过</a>");
			} else if (selectByExample.get(i).getcStatic().equals("1")) {
				c.setcStatic("<a href=\"javascript:table('0','" + selectByExample.get(i).getcId()
						+ "')\"  class=\"layui-btn layui-btn-danger layui-btn-xs\">审核通过</a><a href=\"javascript:table('1','"
						+ selectByExample.get(i).getcId() + "')\" class=\"layui-btn layui-btn-xs\">拒绝通过</a>");
			} else if (selectByExample.get(i).getcStatic().equals("2")) {
				c.setcStatic("<a class=\"layui-btn layui-btn-danger layui-btn-xs\">已通过</a>");
			} else {
				c.setcStatic("<a class=\"layui-btn layui-btn-xs\">拒绝通过</a>");
			}
			list.add(c);
		}
		if (selectByExample.size() > 0) {
			new CallBack().yes(response, list, "");
		} else {
			new CallBack().no(response, list, "");
		}
	}
	/**
	 * @方法名:auditOperation
	 * @方法描述：提现通过或者拒绝通过
	 * @创建时间：2019-03-22 13:07:07
	 * @创建人：王俊
	 * @author Administrator
	 *
	 */
	@RequestMapping("pc/admin/auditOperation")
	public void auditOperation(HttpServletRequest request, HttpServletResponse response) {
		CashManagementTable record=new CashManagementTable();
		record.setcReateEndtime(Uuid.getTime());
		if(request.getParameter("type").equals("1")) {
			record.setcStatic("3");
		}else {
			record.setcStatic("2");
		}
		CashManagementTableExample example=new CashManagementTableExample();
		com.tszs.entity.CashManagementTableExample.Criteria ca=example.createCriteria();
		ca.andCIdEqualTo(request.getParameter("id"));
		int c =cashManagementTableBiz.updateByExampleSelective(record, example);
		if(c>0) {
			new CallBack().yes(response, "", "");
		}else {
			new CallBack().no(response, "", "");
		}
	}
}
